<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单号" prop="tradeNo">
        <el-input
          v-model="queryParams.tradeNo"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="买家昵称" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入买家昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单状态" prop="flag">
        <el-select
          v-model="queryParams.flag"
          placeholder="请选择订单状态"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in [{label:'上传成功',value:'Y'},{label:'上传失败',value:'N'}]"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>

      </el-form-item>
      <el-form-item label="登记时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          icon="el-icon-download"-->
<!--          v-hasPermi="['admin:tradeOrder:export']"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="omsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="序号"
        type="index"
        width="50">
      </el-table-column>
      <el-table-column label="订单ID" align="center" prop="id" />
      <el-table-column label="订单号" align="center" prop="tradeNo" />
      <el-table-column label="买家昵称" align="center" prop="userName" />
      <el-table-column label="登记日期" align="center" prop="createTime" />
      <el-table-column label="订单状态" align="center" prop="result" >
        <template slot-scope="scope">
          <div v-if="scope.row.flag"
               :class="scope.row.flag == 'Y'?'pass':'not-pass'">
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            v-hasPermi="['admin:tradeOrder:delete']"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
<!--    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />-->

    <!-- 添加或修改订单号对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form"  label-width="100px">
        <el-form-item label="订单ID：" prop="sourceTradeNos">
          {{form.id}}
        </el-form-item>
        <el-form-item label="订单号：">
          {{form.tradeNo}}
        </el-form-item>
        <el-form-item label="买家昵称：">
          {{form.userName}}
        </el-form-item>

        <el-form-item label="登记日期：">
          {{form.createTime}}
        </el-form-item>
        <el-form-item label="登记日期：">
          <div v-if="form.flag"
               :class="form.flag == 'Y'?'pass':'not-pass'">
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button type="primary" @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { deleteBusinessApi,
  updateBusinessApi,
  listBusinessApi,
  saveBusinessApi, } from "@/api/business.js";
import {delUser} from "@/api/system/user";
import {listRole} from "@/api/system/role";

export default {
  name: "business",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单号表格数据
      omsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        tradeNo:null,
        userName:null,
        flag:null
      },

      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单号列表 */
    getList() {
      this.loading = true;
      listBusinessApi(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.omsList = response.rows;
        // this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        omsTitle: null,
        omsType: null,
        omsContent: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        tradeNo:null,
        userName:null,
      }
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单号";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      // const id = row.id || this.ids
      // updateBusinessApi(id).then(response => {
      this.form = {...row};
      this.open = true;
      this.title = "查看订单号";
      // });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBusinessApi(this.form).then(response => {
              this.$message.success('修改成功')
              this.open = false;
              this.getList();
            });
          } else {
            saveBusinessApi(this.form).then(response => {
              this.$message.success('新增成功')
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('此操作将永久删除该数据, 是否继续?').then(function() {
        return deleteBusinessApi(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
        this.getList();
      });
    },
    handleBack(){
      this.$router.back()
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('open/export', {
        ...this.queryParams
      }, `oms_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
